import {defineStore} from "pinia";
import {mangaementType} from "@/store/modules/mangement/type";
import type {reportTag} from "@/api/management/type";
import {getTemplateFileConfig, getReportTag, stsReportList, getGenReportfile, getReportfile} from "@/api/management";

// 序号  报告目录 报告名 创建时间 操作
const useMangaementStore = defineStore('mangaementStore', {
        state(): mangaementType {
            return {
                table: {
                    tableHeader: [
                        {
                            name: '报告目录',
                            prop: 'dirPath',
                        },
                        {
                            name: '报告名',
                            prop: 'reportName',
                        },
                        {
                            name: '创建时间',
                            prop: 'createTime',
                        },
                    ],
                    tableData: [],
                    tableLoading: false,
                },
                reportName: '',
                page: 1,
                limit: 20,
                total: 0,
                editTemp: {
                    reportTag: <reportTag>{},
                    tempFileConfig: {},
                    defaultOpen:[]
                }
            }
        },
        actions: {
            async getStsReportList() {
                let params = {
                    page: this.page,
                    limit: this.limit,
                    reportName: this.reportName
                }
                let res = await stsReportList(params)
                console.log(res)
                this.table.tableData = res.data.list
                this.total = res.data.total
            },
            async getReportTagList(id: string) {
                let params = {
                    id: id
                }
                let res = await getReportTag(params)
                this.editTemp.reportTag = res.data
                this.setDefaultOpen()
            },
            async useGetReporstViewstruct(id: string) {
                this.editTemp.tempFileConfig={}
                let params = {
                    id: id
                }
                let res = await getTemplateFileConfig(params)
                this.editTemp.tempFileConfig = res.data
                document.title=res.data.document.title
            },
            async useGetGenReportfile(id: string) {
                this.editTemp.tempFileConfig={}
                let params = {
                    instanceId: id
                }
                let res = await getGenReportfile(params)
                this.editTemp.tempFileConfig = res.data
                document.title=res.data.document.title
            },
            async useGetReportfile(id: string) {
                this.editTemp.tempFileConfig={}
                let params = {
                    instanceId: id
                }
                let res = await getReportfile(params)
                this.editTemp.tempFileConfig = res.data
                document.title=res.data.document.title
            },
            setDefaultOpen(){
                this.editTemp.reportTag.reportDataTagList.forEach((item)=>{
                    this.editTemp.defaultOpen.push(item.name)
                })
                console.log(this.editTemp.defaultOpen)
            }
        }
    }
)
export default useMangaementStore

